var resul = true;
$(document).ready(function() {
	$("#updatePwdBtn").click(function() {
		resul = validateForm();
		if (resul){
			resul = false;
			$.messager.confirm('提示','确认要修改密码吗?', function(r) {
				if (r) {
					$.ajax({
						type : "post",
						url:'system/user/updatePwd.shtml',
						data : {
							"loginPwd" : $("#loginPwd").val()
						},
						dataType : "json",
						async : false,
						success : function(result) {
							if (result == 1) {
								alertInfo("修改成功");
								$('#q').window('close');
							} else {
								alertError("请输入正确的密码");
							}
						}
					});
				}
			});
		}
	});
	$("#oldpassword").bind({
		blur : function() {
			var oldpassword = $("#oldpassword").val();
			$.ajax({
				type : "post",
				url:'system/user/checkPwd.shtml',
				data : {
					"oldpassword" : oldpassword
				},
				dataType : "text",
				async : false,
				success : function(result) {
					if (result == "success") {
						$("#loginPwd").removeAttr("disabled");
						$("#passwordtoo").removeAttr("disabled");
						return true;
					} else {
						alertError("请输入正确的密码");
						$("#loginPwd").attr("disabled","disabled");
						$("#passwordtoo").attr("disabled","disabled");
						return false;
					}
				}
			});
		}
	});
});

function validateForm() {
	var old = $("#oldpassword").val();
	var newDate = $("#loginPwd").val();
	var tooDate = $("#passwordtoo").val();
	if (old == "") {
		alertError("原始密码不能为空");
		return false;
	}
	if (newDate == "") {
		alertError("新密码不能为空");
		return false;
	}
	if (tooDate != newDate) {
		alertError("两次密码不一致");
		return false;
	}
	return true;
}